<template>
    <div class = "OrderAudit">
        <van-cell title = "门店名称" :value = shopDetail.zhicheng />
        <van-cell title = "联系人姓名" :value = shopDetail.realname />
        <van-cell title = "联系电话" :value = shopDetail.phone />
        <van-cell  @click="address.show = true" title = "门店地址" :value = shopDetail.address is-link />
<!--        <van-cell title = " " value = "内容">-->
<!--            <span>地图选址</span>-->
<!--        </van-cell>-->
        <van-cell @click="salesman.show = true" title = "分配业务员" :value = salesman.selectName is-link />
        <van-cell-group>
            <van-field v-model = "value" label = "审核原因" placeholder = "请填写审核原因" />
        </van-cell-group>
        <div class="button-cancel-confirm">
            <div class="cancel" @click="eventClickCancel">拒绝</div>
            <div class="confirm" @click="eventClickConfirm">通过</div>
        </div>
		<!--分配订单-->
		<van-popup v-model="salesman.show" round position="bottom" :style="{ height: '40%' }">
			<van-picker :columns="salesman.listName" @cancel="onCancel" @confirm="onConfirm" show-toolbar title="业务员" />
		</van-popup>
		<van-dialog v-model="address.show" title="修改地址" show-cancel-button @confirm="eventClickChageAddress">
			<van-field v-model="address.path" placeholder="请输入新的地址" />
		</van-dialog>
    </div>
</template>

<script>
    import {Cell, CellGroup, Field, Popup, Picker, Dialog} from 'vant';

    export default {
        name: "OrderAudit",
        components: {
            [Cell.name]: Cell, [CellGroup.name]: CellGroup, [Field.name]: Field,  [Popup.name]: Popup, [Picker.name]: Picker,
            [Dialog.Component.name]: Dialog.Component
        },
        data(){
            return {
                shopDetail:{},
                value:'',
                salesman: {
                    show: false,
                    listName: [], listId: [],
                    selectId: '', selectName: '点击选择为该门店分配业务员', index: ''
                },
                address: {
                    show: false,
                    path: ''
                }
            }
        },
        mounted(){
            this.eventGetAllOrder();
          this.getshopDetail();
        },
        methods:{
            getshopDetail(){
                var url = '/api/home/user/getoneS';
                var param = {
                    id:this.$route.query.id,
                    token:this.$route.query.token
                };
                this.$util.postRequestInterface(url,param,(res)=>{
                    this.shopDetail = res.data;
                })
            },
            eventClickCancel(){
                if (this.value==''){
                    this.$toast('请输入原因！');
                    return false;
                }
                var url = '/api/home/user/confirm';
                var param = {
                    token : this.$route.query.id,
                    status:0,
                    remark:this.value
                };
                this.$util.postRequestInterface(url,param,(res)=>{
                    this.$router.go(-1);
                })
            },
            eventClickConfirm(){
                var url = '/api/home/user/confirm';
                var param = {
                    token : this.$route.query.id,
                    status:1,
                    remark:this.value,
                    saleid: this.salesman.selectId,
                    address: this.salesman.address
                };
                this.$util.postRequestInterface(url,param,(res)=>{
                    this.$router.go(-1);
                })
            },
			//获取所有的业务员
			eventGetAllOrder() {
				var url = '/api/home/user/getall',
					params = {
						token: this.$store.state.options.user.token
					};

				this.$util.postRequestInterface(url, params, (res) => {
					this.salesman.listName = res.data.name;
					this.salesman.listId = res.data.id;
					// console.log(this.salesman);
				});
            },
			//上面的取消按钮
			onCancel() {
				this.salesman.show = false;
			},
			//上面的确定按钮
			onConfirm(value, index) {
                this.salesman.selectId = this.salesman.listId[index];
                this.salesman.selectName = this.salesman.listName[index];
				this.salesman.show = false;
            },
            eventClickChageAddress() {
                if(this.address.path) {
                    this.shopDetail.address = this.address.path;
                }
            }
        }
    }
</script>

<style scoped lang = "scss">
    .OrderAudit {
        /*修改单元格样式*/
        .van-cell__value {
            flex: 2;
            text-align: left;
        }

        .van-cell {
            line-height: 2rem !important;

            &:nth-child(4) {
                .van-cell__value {
                    padding-left: .9rem;
                }
            }
        }

        /*修改多行文本*/
        .van-cell-group {
            height: 15rem;
            border-top: .5rem solid #EEEEEE;
        }

        .button-cancel-confirm{
            display: flex;
            flex: 1;
            position: fixed;
            bottom: 0;
            width: 100%;
            justify-content: center;
            font-size: 1.7rem;
            color: #ffffff;
            &>div{
                flex:1;
                padding: 1rem 0;
                text-align: center;
            }
            .cancel{
                background: #A3A3A3;
            }
            .confirm{
                background: #00CC00;
            }
        }
    }

</style>
